<template>
	<view class="content_box">
		<view class="vide">
			<view class="" style="float: right;" @click="skipVideo">
				<view style="color: #666666;">跳过</view>
			</view>


			<view class="title mt36 ww100">
				<view class=" mt36 ww100" @click="tabNum">
					{{num}}
				</view>
				<view class="ww100 text-center mt60">
					<text>请在拍摄中读出相关数字</text>
				</view>
			</view>

			<view class="ww100 mt80">

				<view v-if="src" class="w570 h420 r20 flex justify-center " style="margin: auto;">
					<video style="margin: auto; border-radius: 20;" :src="src"></video>
				</view>
				<view v-else class="w570 h420 r20 flex justify-center"
					style="background-color: #F5F5F5; margin: 0 auto;" @click="videoInput">
					<view class="cuIcon-add" style="margin: auto; font-size: 90rpx; color: #B3B3B3;"></view>
				</view>


				<view class="w403" style="margin: 41rpx auto 155rpx;">
					请拍摄真人视频10秒,以确保与本 人相符合，保证视频清晰可见
				</view>

				<view class="w570 h80 lh80 text-center r40" @click="submit"
					style="background: #000000; margin: 0 auto;">
					<text style="color: #FFFFFF;">提交</text>
				</view>
			</view>
		</view>
		<view class="foot_box"></view>
		<!-- 加载提示 -->
		<yy-loading text="加载中.." mask="true" click="true" ref="loading"></yy-loading>
		<!-- 信息提示-->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: '',
				num: '',
				sex: '',
			};
		},
		onShow() {},
		onLoad(e) {
			// this.getUserInfo()
			this.sex = uni.getStorageSync('sex')
			// sex 等于 0 表示女 不能跳过 
			this.tabNum()

		},
		methods: {

			skipVideo() {
				// this.l.to('/pages/tab/index')
				this.l.to('/pages/register/login?textFont=' + 1)
			},

			tabNum() {
				this.num = ''
				this.randomNum(1, 6)
			},

			randomNum(max, min) {
				for (var idx = 0; idx < 6; idx++) {
					this.num += parseInt(Math.random() * 9);
				}
			},

			videoInput() {
				var obj = {}
				var _this = this
				var imgUrl = ''
				uni.chooseVideo({
					count: 1,
					sourceType: ['camera', 'album'],
					compressed: false,
					maxDuration: 12,
					success: function(res) {
						_this.imgUrl = res.tempFilePath
						uni.uploadFile({
							url: _this.UPLOADFILE,
							async: true,
							filePath: _this.imgUrl,
							name: 'file',
							success: (res) => {
								obj = JSON.parse(res.data)
								_this.src = obj.data
								console.log("this.returnImage", _this.src)
							},
						});
					}
				});
			},

			async submit() {
				console.log('src==>', this.src);
				const res = await this.$u.post('/api/user/video/add', {
					id: uni.getStorageSync('user').id,
					uid: uni.getStorageSync('user').id,
					code: this.num,
					userUploadVideo: this.src,
				})
				this.l.msgg(res.msg)
				if (res.code == 200) {
					this.l.msgg(res.msg)
					// this.l.to('/pages/tab/index')
					this.l.to('/pages/register/login')
				}
			},
		}
	};
</script>

<style lang="scss" scoped>
	.content_box {
		padding: 128rpx 31rpx;

		.vide {

			.title {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #000000;
				overflow: hidden;
				text-align: center;
			}
		}
	}
</style>
